package com.qk.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qk.common.PageResult;
import com.qk.dto.opetate_log.OperateLogDTO;
import com.qk.entity.OperateLog;
import com.qk.entity.User;
import com.qk.enums.ParamEnum;
import com.qk.exception.CommonException;
import com.qk.mapper.UserMapper;
import com.qk.service.OperateLogService;
import com.qk.mapper.OperateLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author SweetHurt
* @description 针对表【operate_log(操作日志表)】的数据库操作Service实现
* @createDate 2025-10-17 20:36:15
*/
@Service
public class OperateLogServiceImpl extends ServiceImpl<OperateLogMapper, OperateLog>
    implements OperateLogService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public PageResult<OperateLog> getLogByPage(OperateLogDTO dto) {
        List<User> list = userMapper.selectByName(dto.getOperateUserName());
        if(ObjectUtil.isEmpty(list)) {
            CommonException.throwException(ParamEnum.PARAM_ERROR);
        }
        Page<OperateLog> page = page(new Page<>(dto.getPage(), dto.getPageSize()), Wrappers.<OperateLog>lambdaQuery()
                .in(OperateLog::getOperateUserId, list.stream().map(User::getId).collect(Collectors.toList())));
        return PageResult.<OperateLog>builder()
                .total(Long.valueOf(page.getTotal()).intValue())
                .rows(page.getRecords())
                .build();
    }
}




